// API基础配置
const BASE_URL = 'http://120.26.210.23:8888/jeecgboot/';

// 请求封装
const request = (options) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: BASE_URL + options.url,
      method: options.method || 'GET',
      data: options.data || {},
      header: {
        'content-type': 'application/json',
        // 'X-Access-Token':
        //   'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZXhwIjoxNzYyMTA4OTc4fQ.ffeUucOca-Xy2UK85xYYJ2Tp2Eh_K_VduS336ylg6hg',
        ...options.header
      },
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          uni.showToast({
            icon: 'none',
            title: res.data.message || '请求失败'
          });
          reject(res);
        }
      },
      fail: (err) => {
        uni.showToast({
          icon: 'none',
          title: '网络请求失败'
        });
        reject(err);
      }
    });
  });
};

export default request;
